import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-03-11
 * Time: 21:24
 */
public class Test {
    //数组是否连续出现三个奇数
    public static boolean func5(int[] arr){
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] % 2 != 0){
                count++;
                if(count == 3){
                    return true;
                }
            }else{
                count = 0;
            }
        }
        return false;
    }
    public static void main(String[] args) {
        int[] arr = { 1 ,2 ,3 , 5 , 7 , 9 , 10};
        boolean ret = func5(arr);
        System.out.println(ret);
    }
    //找出数组的多数元素 占一半多
    public static int func4(int[] arr){
        return arr[arr.length / 2];
    }
    public static void main4(String[] args) {
        int[] arr = { 1 ,1  ,2 ,2 ,2};
        int ret = func4(arr);
        System.out.println(ret);
    }
    //找出数组只出现1次的数字
    //知识：0 ^ n = n  ,  n ^ n = 0
    public static int func3(int[] arr){
        int ret = 0;
        for (int i = 0; i < arr.length; i++) {
            ret ^= arr[i];
        }
        return ret;
    }
    public static void main3(String[] args) {
        int[] arr ={ 1 , 2 , 2, 1 ,3};
        int ret = func3(arr);
        System.out.println(ret);
    }
    //在一个数组中找出两个数的和等于目标值并返回下标 同意个元素不能同时出现
    public static int[] func2(int[] arr,int n){
        int[] ret = { -1, -1};
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if(arr[i] + arr[j] == n){
                    ret[0] = i;
                    ret[1] = j;
                }
            }
        }
        return ret;
    }
    public static void main2(String[] args) {
        int[] arr = {2 ,3 , 7 ,11 , 15};
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] ret = func2(arr, n);
        System.out.println(Arrays.toString(ret));
    }
    //奇数在偶数前
    public static void func(int[] arr){
        int left = 0;
        int right = arr.length - 1;
        while(left <right){
            while(left <right && arr[left] % 2 != 0){
                left++;
            }
            while(left <right && arr[right] % 2 == 0){
                right--;
            }
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
        }
    }
    public static void main1(String[] args) {
        int[] arr = {1,  2, 3 ,4 ,5 ,6};
        func(arr);
        System.out.println(Arrays.toString(arr));
    }
}
